import os

from v1.TemplateLoader import TemplateLoader
from v1.DataCollector import DataCollector
from v1.CodeGenerateMachine import CodeGenerateMachine

path = os.path.join(os.path.dirname(__file__), "swagger.json")

tpl = TemplateLoader().package_load("axios", "templates", "get.tpl")
data = DataCollector().collect_json(path)
result = ""
for path, info in data.items():
    render_data = {"url": path}
    for method, methodInfo in info.items():
        render_data["method"] = method
        render_data["label"] = methodInfo.get("summary")
        render_data["params"] = methodInfo.get("parameters")
        operationId = methodInfo.get("operationId")
        apiName = "".join(operationId.split("-"))
        render_data["apiName"] = apiName
        result += "\n\n"
        result += CodeGenerateMachine().render(template=tpl,data=render_data)
print(result)
